//--------------Sonic CD Rotating Spikes Script-----.---------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
#alias Object.Value0	:	Object.Angle


sub ObjectMain
	Object.Angle += 2
	Object.Angle &= 511
end sub


sub ObjectPlayerInteraction
	TempValue0   = 0

	TempValue1   = Object.PropertyValue
	TempValue1 <<= 4

	TempValue2   = Object.XPos
	TempValue3   = Object.YPos

	Cos(Object.XPos, Object.Angle)
	Object.XPos  *= TempValue1
	Object.XPos <<= 7
	Object.XPos  += TempValue2

	Sin(Object.YPos, Object.Angle)
	Object.YPos  *= TempValue1
	Object.YPos <<= 7
	Object.YPos  += TempValue3

	PlayerObjectCollision(C_TOUCH, -12, -12, 12, 12)
	if CheckResult == true
		CallFunction(Player_Hit)
	end if

	Object.XPos = TempValue2
	Object.YPos = TempValue3
end sub


sub ObjectDraw
	DrawSprite(0)
	TempValue0 = 0
	TempValue1 = 16

	TempValue4 = Object.PropertyValue
	TempValue4--
	while TempValue0 < TempValue4
		Cos(TempValue2, Object.Angle)
		TempValue2  *= TempValue1
		TempValue2 <<= 7
		TempValue2  += Object.XPos

		Sin(TempValue3, Object.Angle)
		TempValue3  *= TempValue1
		TempValue3 <<= 7
		TempValue3  += Object.YPos
		DrawSpriteXY(1, TempValue2, TempValue3)

		TempValue0++
		TempValue1 += 16
	loop

	Cos(TempValue2, Object.Angle)
	TempValue2  *= TempValue1
	TempValue2 <<= 7
	TempValue2  += Object.XPos

	Sin(TempValue3, Object.Angle)
	TempValue3  *= TempValue1
	TempValue3 <<= 7
	TempValue3  += Object.YPos
	DrawSpriteXY(2, TempValue2, TempValue3)
end sub


sub ObjectStartup
	LoadSpriteSheet("R2/Objects2.gif")
	
	SpriteFrame(-8, -8, 16, 16, 230, 52)		// #0 - Connection Joint
	SpriteFrame(-8, -8, 16, 16, 230, 69)		// #1 - Chain
	SpriteFrame(-16, -16, 32, 32, 133, 169)	// #2 - Spike Ball
end sub


// ========================
// Editor Subs
// ========================

sub RSDKDraw
	DrawSprite(0)
	TempValue0 = 0
	TempValue1 = 16

	TempValue4 = Object.PropertyValue
	TempValue4--
	while TempValue0 < TempValue4
		Cos(TempValue2, Object.Angle)
		TempValue2  *= TempValue1
		TempValue2 <<= 7
		TempValue2  += Object.XPos

		Sin(TempValue3, Object.Angle)
		TempValue3  *= TempValue1
		TempValue3 <<= 7
		TempValue3  += Object.YPos
		DrawSpriteXY(1, TempValue2, TempValue3)

		TempValue0++
		TempValue1 += 16
	loop

	Cos(TempValue2, Object.Angle)
	TempValue2  *= TempValue1
	TempValue2 <<= 7
	TempValue2  += Object.XPos

	Sin(TempValue3, Object.Angle)
	TempValue3  *= TempValue1
	TempValue3 <<= 7
	TempValue3  += Object.YPos
	DrawSpriteXY(2, TempValue2, TempValue3)
end sub


sub RSDKLoad
	LoadSpriteSheet("R4/Objects.gif")
	
	SpriteFrame(-8, -8, 16, 16, 163, 52)	// #0 - Spike Joint
	SpriteFrame(-8, -8, 16, 16, 180, 52)	// #1 - Chain
	SpriteFrame(-16, -16, 32, 32, 221, 53)	// #2 - Spike Ball

	SetVariableAlias(ALIAS_VAR_PROPVAL, "chainAmount")
end sub
